package com.equalsandhashcode;

import java.util.HashSet;

public class CustomerExample {
	private int cid;
	private String cname;
	
	public CustomerExample(){
		
	}
	public CustomerExample(int cid,String cname){
		this.cid=cid;
		this.cname=cname;
	}
public int getCid() {
		return cid;
	}

	public void setCid(int cid) {
		this.cid = cid;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}
	public String toString(){
		return cid+"\t"+cname;
	}
	public int hashCode(){
		String id=Integer.toString(cid);
		int hashId=id.hashCode();
		int hashName=cname.hashCode();
		int hash=hashId+hashName;
		return hash;
	}
	public boolean equals(Object obj){
		CustomerExample cust=(CustomerExample)obj;
		
		return this.cid==cust.cid && this.cname==cust.cname;
	}

public static void main(String[] args) {
	CustomerExample c1=new CustomerExample(101,"deepak");
	CustomerExample c2=new CustomerExample(101,"deepak");
	HashSet hs=new HashSet();
	hs.add(c1);
	hs.add(c2);
	System.out.println(hs);
	System.out.println(c1==c2);
	System.out.println(c1.equals(c2));
}
}
